/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package intopo.evogame.partnerselection.config;

import intopo.game.Description;
import java.lang.reflect.InvocationTargetException;

/**
 * Thrown to indicate that a problem occurred while constructing a game.  This exception stores a description of the game
 * that was used to obtain a {@code Constructor} instance.  It also stores the problem cause, an exception throw when invoking
 * method {@code newInstance()} of class {@code Constructor}
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0
 *
 * @see java.lang.reflect.Constructor#newInstance(java.lang.Object[])
 */
public class ConstructGameException
	extends Exception
{
	/**
	 * The tag name of the constructor that was used to fetch the constructor that caused this exception.
	 */
	final private String tagname;

	public ConstructGameException (String tagname, InstantiationException e)
	{
		super (e);
		this.tagname = tagname;
	}
	public ConstructGameException (String tagname, IllegalAccessException e)
	{
		super (e);
		this.tagname = tagname;
	}
	public ConstructGameException (String tagname, IllegalArgumentException e)
	{
		super (e);
		this.tagname = tagname;
	}
	public ConstructGameException (String tagname, InvocationTargetException e)
	{
		super (e);
		this.tagname = tagname;
	}
	/**
	 * Get the canonical name of the game description that was used to obtain a constructor.
	 * @return
	 */
	public String getDescription ()
	{
		return this.tagname;
	}
	public String getUserMessage ()
	{
		StringBuffer result = new StringBuffer (37 + 1024 + 14 + 2000);
		result.append ("Error creating an instance of game associated to tag '");
		result.append (this.tagname);
		result.append ("\nCause was:\n");
		result.append (this.getCause ());
		return result.toString ();
	}
}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
